package com.augurit.gzcgwsp.ljzyz.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.ljzyz.entity.YwYnLjzyzSqb;
import com.augurit.gzcgwsp.ljzyz.web.form.YwYnLjzyzSqbForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

public class YwYnLjzyzSqbConvertor {
	public static YwYnLjzyzSqbForm convertVoToForm(YwYnLjzyzSqb entity) {
		if(entity != null) {
			YwYnLjzyzSqbForm form = new DozerBeanMapper().map(entity, YwYnLjzyzSqbForm.class);
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(YwYnLjzyzSqbForm form, YwYnLjzyzSqb entity) {
		if(entity != null && form != null) {
			if(form.getYwlxr() != null && form.getYwlxr().trim().length() > 0)
				entity.setYwlxr(form.getYwlxr().trim());
			if(form.getSqsx() != null && form.getSqsx().trim().length() > 0)
				entity.setSqsx(form.getSqsx().trim());
			entity.setId(form.getId());
			if(form.getSqdw() != null && form.getSqdw().trim().length() > 0)
				entity.setSqdw(form.getSqdw().trim());
			entity.setLarq(form.getLarq());
			entity.setSarq(form.getSarq());
			if(form.getJar() != null && form.getJar().trim().length() > 0)
				entity.setJar(form.getJar().trim());
			entity.setJarq(form.getJarq());
			entity.setQyid(form.getQyid());
			if(form.getSendNotice() != null && form.getSendNotice().trim().length() > 0)
				entity.setSendNotice(form.getSendNotice().trim());
			if(form.getYslNo() != null && form.getYslNo().trim().length() > 0)
				entity.setYslNo(form.getYslNo().trim());
			if(form.getHbbm() != null && form.getHbbm().trim().length() > 0)
				entity.setHbbm(form.getHbbm().trim());
			if(form.getIsycbl() != null && form.getIsycbl().trim().length() > 0)
				entity.setIsycbl(form.getIsycbl().trim());
			entity.setSqrq(form.getSqrq());
			if(form.getYwlxrtel() != null && form.getYwlxrtel().trim().length() > 0)
				entity.setYwlxrtel(form.getYwlxrtel().trim());
			if(form.getSqsx() != null && form.getSqsx().trim().length() > 0)
				entity.setSqsx(form.getSqsx().trim());
			if(form.getZyzhm() != null && form.getZyzhm().trim().length() > 0)
				entity.setZyzhm(form.getZyzhm().trim());
			if(form.getYwkfzr() != null && form.getYwkfzr().trim().length() > 0)
				entity.setYwkfzr(form.getYwkfzr().trim());
			if(form.getAcceptNo() != null && form.getAcceptNo().trim().length() > 0)
				entity.setAcceptNo(form.getAcceptNo().trim());
			if(form.getCbyw() != null && form.getCbyw().trim().length() > 0)
				entity.setCbyw(form.getCbyw().trim());
			if(form.getCbbm() != null && form.getCbbm().trim().length() > 0)
				entity.setCbbm(form.getCbbm().trim());
			if(form.getSjr() != null && form.getSjr().trim().length() > 0)
				entity.setSjr(form.getSjr().trim());
			entity.setCpsj(form.getCpsj());
			entity.setDfsj(form.getDfsj());
			if(form.getJbrxm() != null && form.getJbrxm().trim().length() > 0)
				entity.setJbrxm(form.getJbrxm().trim());
			if(form.getYsgsqsr() != null && form.getYsgsqsr().trim().length() > 0)
				entity.setYsgsqsr(form.getYsgsqsr().trim());
			entity.setId(form.getId());
			if(form.getSqdw() != null && form.getSqdw().trim().length() > 0)
				entity.setSqdw(form.getSqdw().trim());
			entity.setLarq(form.getLarq());
			entity.setSarq(form.getSarq());
			if(form.getJar() != null && form.getJar().trim().length() > 0)
				entity.setJar(form.getJar().trim());
			entity.setJarq(form.getJarq());
			entity.setAddress(form.getAddress());
			if(form.getCzzh() != null && form.getCzzh().trim().length() > 0)
				entity.setCzzh(form.getCzzh().trim());
			if(form.getBz() != null && form.getBz().trim().length() > 0)
				entity.setBz(form.getBz().trim());
			if(form.getLxr() != null && form.getLxr().trim().length() > 0)
				entity.setLxr(form.getLxr().trim());
			if(form.getLxTel() != null && form.getLxTel().trim().length() > 0)
				entity.setLxTel(form.getLxTel().trim());
			if(form.getZyzbh() != null && form.getZyzbh().trim().length() > 0)
				entity.setZyzbh(form.getZyzbh().trim());
			if(form.getFzr() != null && form.getFzr().trim().length() > 0)
				entity.setFzr(form.getFzr().trim());
			if(form.getCheckCarDate() != null)
				entity.setCheckCarDate(form.getCheckCarDate());
			if(StringUtils.isNotBlank(form.getCheckCarLeader()))
				entity.setCheckCarLeader(form.getCheckCarLeader());
			if(StringUtils.isNotBlank(form.getCheckCarPerson()))
				entity.setCheckCarPerson(form.getCheckCarPerson());
			
		}
	}
	
	public static List<YwYnLjzyzSqbForm> convertVoListToFormList(List<YwYnLjzyzSqb> ywYnLjzyzSqbList) {
		if(ywYnLjzyzSqbList != null && ywYnLjzyzSqbList.size() > 0) {
			List<YwYnLjzyzSqbForm> ywYnLjzyzSqbFormList = new ArrayList();
			for(int i=0; i<ywYnLjzyzSqbList.size(); i++) {
				ywYnLjzyzSqbFormList.add(convertVoToForm(ywYnLjzyzSqbList.get(i)));
			}
			return ywYnLjzyzSqbFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<YwYnLjzyzSqb> ywYnLjzyzSqbList) {
		if(ywYnLjzyzSqbList != null && ywYnLjzyzSqbList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywYnLjzyzSqbList.size(); i++) {
				YwYnLjzyzSqb entity = ywYnLjzyzSqbList.get(i);
				Map<String, String> map = new HashMap();

				map.put("ywlxrtel", entity.getYwlxrtel());
				map.put("address", entity.getAddress());
				map.put("ywlxr", entity.getYwlxr());
				map.put("sqsx", entity.getSqsx());
				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("sqdw", entity.getSqdw());
				map.put("larq", DateUtils.dateTimeToString(entity.getLarq(), "yyyy-MM-dd"));
				map.put("sarq", DateUtils.dateTimeToString(entity.getSarq(), "yyyy-MM-dd"));
				map.put("jar", entity.getJar());
				map.put("jarq", DateUtils.dateTimeToString(entity.getJarq(), "yyyy-MM-dd"));
				map.put("qyid", entity.getQyid() == null ? "" : entity.getQyid().toString());
				map.put("sendNotice", entity.getSendNotice());
				map.put("yslNo", entity.getYslNo());
				map.put("hbbm", entity.getHbbm());
				map.put("isycbl", entity.getIsycbl());
				map.put("sqrq", DateUtils.dateTimeToString(entity.getSqrq(), "yyyy-MM-dd"));
				map.put("sqsx", entity.getSqsx());
				map.put("zyzhm", entity.getZyzhm());
				map.put("ywkfzr", entity.getYwkfzr());
				map.put("acceptNo", entity.getAcceptNo());
				map.put("cbyw", entity.getCbyw());
				map.put("cbbm", entity.getCbbm());
				map.put("sjr", entity.getSjr());
				map.put("cpsj", DateUtils.dateTimeToString(entity.getCpsj(), "yyyy-MM-dd"));
				map.put("dfsj", DateUtils.dateTimeToString(entity.getDfsj(), "yyyy-MM-dd"));
				map.put("jbrxm", entity.getJbrxm());
				map.put("ysgsqsr", entity.getYsgsqsr());
				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("sqdw", entity.getSqdw());
				map.put("larq", DateUtils.dateTimeToString(entity.getLarq(), "yyyy-MM-dd"));
				map.put("sarq", DateUtils.dateTimeToString(entity.getSarq(), "yyyy-MM-dd"));
				map.put("jar", entity.getJar());
				map.put("jarq", DateUtils.dateTimeToString(entity.getJarq(), "yyyy-MM-dd"));
				map.put("czzh", entity.getCzzh());
				map.put("bz", entity.getBz());
				map.put("lxr", entity.getLxr());
				map.put("lxTel", entity.getLxTel());
				map.put("zyzbh", entity.getZyzbh());
				map.put("fzr", entity.getFzr());
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwYnLjzyzSqb> convertFormListToVoList(List<YwYnLjzyzSqbForm> ywYnLjzyzSqbFormList) {
		if(ywYnLjzyzSqbFormList != null && ywYnLjzyzSqbFormList.size() > 0) {
			List<YwYnLjzyzSqb> ywYnLjzyzSqbList = new ArrayList();
			for(int i=0; i<ywYnLjzyzSqbFormList.size(); i++) {
				YwYnLjzyzSqb ywYnLjzyzSqb = new YwYnLjzyzSqb();
				convertFormToVo(ywYnLjzyzSqbFormList.get(i), ywYnLjzyzSqb);
				ywYnLjzyzSqbList.add(ywYnLjzyzSqb);
			}
			return ywYnLjzyzSqbList;
		}
		return null;
	}
	
	public static void convertFormToQyxxForm(YwYnLjzyzSqbForm form, YwComQyxxForm qyxxForm) {
	    if (form == null) return;
	    if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
	}
	
	public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwYnLjzyzSqbForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwYnLjzyzSqbForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQyid(qyxxForm.getId());
    }
}